package org.apache.ocean.main.search.tag;

import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.index.TermFreqVector;
import org.apache.lucene.index.TermPositions;
import org.apache.lucene.index.TermVectorMapper;

// TODO: need overridden parallel reader of deleted docs methods to call only main index reader
public class TagIndexReader extends IndexReader {
	private TagIndex tagIndex;
	private IndexReader mainIndexReader;

	public TagIndexReader(IndexReader mainIndexReader) {
		this.mainIndexReader = mainIndexReader;
	}

	public TermDocs termDocs() throws IOException {
		return tagIndex.getTermPositions();
	}

	public TermPositions termPositions() throws IOException {
		return tagIndex.getTermPositions();
	}

	public TermEnum terms() throws IOException {
		return tagIndex.getTermEnum();
	}

	public TermEnum terms(Term term) throws IOException {
		return tagIndex.getTermEnum(term);
	}

	public int docFreq(Term term) throws IOException {
		return terms(term).docFreq();
	}

	public Document document(int doc, FieldSelector fieldSelector) throws CorruptIndexException, IOException {
		return tagIndex.document(doc);
	}

	/**
	 * not implemented properly
	 */
	public Collection getFieldNames(FieldOption fieldOption) {
		return tagIndex.getFieldNames();
	}

	/**
	 * not sure if this class will keep track of deleted docs
	 */
	public int numDocs() {
		return mainIndexReader.numDocs();
	}

	public boolean hasDeletions() {
		return mainIndexReader.hasDeletions();
	}

	public boolean isDeleted(int doc) {
		return mainIndexReader.isDeleted(doc);
	}

	public int maxDoc() {
		return mainIndexReader.maxDoc();
	}

	/**
	 * Close file handlers
	 */
	protected void doClose() throws IOException {
	}

	/**
	 * Unsupported
	 */
	protected void doCommit() throws IOException {
	}

	/**
	 * Unsupported
	 */
	protected void doDelete(int docNum) throws CorruptIndexException, IOException {
	}

	/**
	 * Unsupported
	 */
	protected void doSetNorm(int doc, String field, byte value) throws CorruptIndexException, IOException {
	}

	protected void doUndeleteAll() throws CorruptIndexException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * Unsupported
	 */
	public TermFreqVector getTermFreqVector(int docNumber, String field) throws IOException {
		return null;
	}

	/**
	 * Unsupported
	 */
	public void getTermFreqVector(int docNumber, String field, TermVectorMapper mapper) throws IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * Unsupported
	 */
	public void getTermFreqVector(int docNumber, TermVectorMapper mapper) throws IOException {
	}

	/**
	 * Unsupported
	 */
	public TermFreqVector[] getTermFreqVectors(int docNumber) throws IOException {
		return null;
	}

	/**
	 * Unsupported
	 */
	public byte[] norms(String field) throws IOException {
		return null;
	}

	/**
	 * Unsupported
	 */
	public void norms(String field, byte[] bytes, int offset) throws IOException {
	}
}
